package com.sport.facilities.booking.system.httptask;

import android.content.Context;

import com.sport.facilities.booking.system.htmlchecker.CancelBookingResultChecker;
import com.sport.facilities.booking.system.htmlchecker.MakeBookingResultChecker;
import com.sport.facilities.booking.system.model.Booking;
import com.sport.facilities.booking.system.model.MakeBookFormModel;

public class MakeBookingResultTask extends BasicTask {
	private final String TAG = "MakeBookingResultTask";
	public MakeBookingResultTask(Context ctx, OnTaskCompleted completeAction) {
		super(ctx);
		this.listener = completeAction;
	}

	public void fnMakeBooking(Booking bm, MakeBookFormModel bfm) {
		try {
			super.onPreExecute();
			super.execute(PATH_BOOK_SUBMIT, bm, bfm);
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		MakeBookingResultChecker brChecker = new MakeBookingResultChecker();
		try {
			boolean isCancelSuccess = brChecker.getBookingResultfromHtml(result);
			if (isCancelSuccess) {
				this.listener.onTaskCompleted(isCancelSuccess);
			} else {
				this.listener.onTaskFailed("Booking is not successful...");
			}
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
		
	}

}
